var t = getApp(), e = require("../../../utils/util.js"), o = t.globalData.url;

Page({
    data: {
        domain: o,
        id: "",
        disamount: "",
        deductAmountAmount: "",
        totalamount: "",
        coupons: [ {
            bizName: "雷龙洗车",
            deductAmountAmount: 20
        }, {
            bizName: "雷龙洗车",
            deductAmountAmount: 20
        }, {
            bizName: "雷龙洗车",
            deductAmountAmount: 20
        } ],
        selectCouponsId: ""
    },
    onLoad: function(t) {
        var e = t.id;
        this.getOrderInfo(e), this.getCoupons(e);
    },
    onReady: function() {},
    onShow: function() {},
    getOrderInfo: function(o) {
        var n = this, a = t.globalData.token;
        e.request(t, "wx/cust/getOneByServiceOrderId", "POST", {
            serviceOrderId: o,
            token: a
        }, function(t) {
            n.setData({
                totalamount: t.data.totalAmount,
                discountPrice: t.data.discountPrice,
                debateAmount: e.convertMath(t.data.debateAmount),
                id: t.data.serviceOrderId
            });
        }, function(t) {});
    },
    getCoupons: function(o) {
        var n = this, a = t.globalData.token;
        e.request(t, "wx/mkt/getmktCouponByserviceOrderId", "POST", {
            serviceOrderId: o,
            token: a
        }, function(t) {
            n.setData({
                coupons: t.data
            }), n.data.coupons.forEach(function(t) {
                return t.isSeleted = !1;
            });
        }, function(t) {});
    },
    checkboxChange: function(t) {
        var e = this.data.coupons;
        e.forEach(function(t) {
            return t.isSeleted = !1;
        });
        var o = t.detail.value[t.detail.value.length - 1];
        o >= 0 && (e[Number(o)].isSeleted = !0), this.setData({
            coupons: e,
            selectCouponsId: e[o].couponId,
            deductAmountAmount: e[o].deductAmountAmount
        });
    },
    wxPay: function(o) {
        var n = this, a = n.data.id, u = n.data.selectCouponsId;
        a ? e.wxpay(t, a, u, "/pages/service/index") : wx.showModal({
            title: "错误",
            content: "无法获取用户资金信息",
            showCancel: !1
        });
    }
});